package com.mall.manager.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.WebUtils;

import com.mall.manager.service.GardenService;
import com.mall.untils.Page;
import com.mall.untils.StringUtil;

/**
 * 查询
 * @ClassName: GardenController
 * @Description: 
 * @author:wangwenyue wangwenyue@ide365.com
 * @date 2016年7月11日 下午5:33:39
 */
@Controller
@RequestMapping("/manager")
public class GardenController {
	
	Logger logger=LoggerFactory.getLogger(DiffPeopleController.class);
	
	@Resource
	private GardenService gardenService;
	
	/**
	 * 分页显示单个园所列表 ，按园所类型、园所名称（ID）查询
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/queryPageGarden")
	public String queryPage(HttpServletRequest request, ModelMap modelMap) {
		Map<String, Object> paraMap = WebUtils.getParametersStartingWith(request, "");
		Page page = gardenService.queryPage(paraMap);
		
		if(null!=page){
			if(paraMap.get("name")!=null &&StringUtils.isNotBlank(String.valueOf(paraMap.get("name")))){
				modelMap.addAttribute("searchName",StringUtil.getByteToString(String.valueOf(paraMap.get("name"))));
			}
	     	modelMap.addAttribute("data", (List<Map<String,Object>>)page.getResult());
	     	int totalpagecount = page.getTotalPageCount();
	     	modelMap.addAttribute("totalpagecount", totalpagecount);
	     	int currentpageno = page.getCurrentPageNo();
	     	modelMap.addAttribute("currentpageno", currentpageno);
	     	int previouspage = page.getCurrentPageNo() <= 1 ? 1 : page
					.getCurrentPageNo() - 1;
	     	modelMap.addAttribute("previouspage", previouspage);
	     	int nextpage = page.getCurrentPageNo() >= page.getTotalPageCount() ? page
					.getTotalPageCount() : page.getCurrentPageNo() + 1;
			modelMap.addAttribute("nextpage", nextpage); 
			List<Integer> showNumList = page.getShowNumList();
			modelMap.addAttribute("pagenumlist", showNumList);
     	}
		return "view/nationwide_counts_list";
	}
	
	
}
